<template>
    <div class="contain-box">
        <div class="box-header">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>客户管理</el-breadcrumb-item>
                <el-breadcrumb-item to="/allCustomers" replace>所有客户</el-breadcrumb-item>
                <el-breadcrumb-item>新增客户</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div class="box-body">
            <div class="box-nav">基础信息</div>
            <div class="body-set">
                <el-input v-model="addObj.customerCode" placeholder="客户编号" style="width: 300px;margin-right: 3px"
                          size="small"></el-input>
                <el-input v-model="addObj.name" placeholder="请输入客户名称" style="width: 300px;margin-right: 3px"
                          size="small"></el-input>
                <el-select v-model="addObj.levelId" placeholder="请选择客户级别" size="small" style="width: 300px;">
                    <el-option v-for="item in levelList" :key="item.id" :label="item.name"
                               :value="item.id"></el-option>
                </el-select>
            </div>
            <div class="body-set">
                <!--                province="河北省" city="石家庄市" area="长安区"-->
                <v-distpicker :placeholders="placeholders"
                              @province="onChangeProv"
                              @city="onChangeCity"
                              @area="onChangeArea"></v-distpicker>
            </div>
            <div class="body-set">
                <el-input v-model="addObj.fullAddress" placeholder="请输入详细地址" style="width: 906px;"
                          size="small"></el-input>
            </div>
            <div class="body-set">
                <el-select v-model="addObj.industryId" placeholder="请选择所属行业" size="small" style="width: 300px;">
                    <el-option v-for="item in industryList" :key="item.id" :label="item.name"
                               :value="item.id"></el-option>
                </el-select>
            </div>
            <div class="box-nav" style="margin-top: 20px">联系人信息</div>
            <div class="body-set">
                <el-input v-model="addObj.contactPerson" placeholder="联系姓名" style="width: 300px;margin-right: 3px"
                          size="small"></el-input>
                <el-input v-model="addObj.phone" placeholder="手机号码" style="width: 300px;margin-right: 3px"
                          size="small"></el-input>
                <el-input v-model="addObj.position" placeholder="部门职务" style="width: 300px;margin-right: 3px"
                          size="small"></el-input>
            </div>
            <div class="body-set">
                <el-input v-model="addObj.role" placeholder="角色" style="width: 300px;margin-right: 3px"
                          size="small"></el-input>
                <el-input v-model="addObj.email" placeholder="电子邮箱" style="width: 300px;margin-right: 3px"
                          size="small"></el-input>
                <el-input v-model="addObj.qq" placeholder="QQ号码" style="width: 300px;margin-right: 3px"
                          size="small"></el-input>
            </div>
        </div>
        <div class="box-submit">
            <div class="submit-left">
            </div>
            <div>
                <el-button size="small" @click="goBack">取 消</el-button>
                <el-button @click="submitAdd" type="primary" size="small" style="background-color: #1abc9c">保存并新增
                </el-button>
            </div>
        </div>
    </div>
</template>

<script>
    import VDistpicker from 'v-distpicker'

    export default {
        components: {VDistpicker},
        data() {
            return {
                placeholders: {
                    province: '请选择所在省份',
                    city: '请选择所在市区',
                    area: '请选择所在县城或区',
                },
                select: {province: null, city: null, area: null},
                industryList: [],
                levelList: [],
                addObj: {}
            }

        },
        created() {
            this.getAllLevel()
            this.getAllIndustry()
        },
        methods: {
            submitAdd() {
                if (!this.select.province || this.select.province === '请选择所在省份') {
                    return this.$message.warning('请选择所在省份')
                }
                if (!this.select.city || this.select.city === '请选择所在市区') {
                    return this.$message.warning('请选择所在市区')
                }
                if (!this.select.area || this.select.area === '请选择所在县城或区') {
                    return this.$message.warning('请选择所在县城或区')
                }
                this.addObj.region = this.select.province + ',' + this.select.city + ',' + this.select.area
                this.axios.post('/customer/save', this.addObj).then(res => {
                    if (res.data.code === 200) {
                        this.goBack()
                        this.$message.success('新增成功')
                    }
                })
            },
            goBack() {
                this.$router.go(-1)
            },
            onChangeProv(e) {
                console.log("省", e);
                this.select.province = e.value
                this.select.city = '请选择所在市区'
                this.select.area = '请选择所在县城或区'
            },
            onChangeCity(e) {
                console.log("市", e);
                this.select.city = e.value
                this.select.area = '请选择所在县城或区'
            },
            onChangeArea(e) {
                console.log("县", e);
                this.select.area = e.value
            },
            //查询全部级别
            getAllLevel() {
                this.axios.post('/customerLevel/findAll?name=' + 1).then(res => {
                    if (res.data.code === 200) {
                        this.levelList = res.data.data
                    }
                })
            },
            //查询全部行业
            getAllIndustry() {
                this.axios.post('/customerIndustry/findAll').then(res => {
                    if (res.data.code === 200) {
                        this.industryList = res.data.data
                    }
                })
            }
        }
    }
</script>

<style scoped lang="less">
    .contain-box {
        width: 100%;
        height: 100%;

        /deep/ .distpicker-address-wrapper {
            select {
                width: 300px !important;
                padding: 0px 10px !important;
                height: 35px !important;
                font-size: 12px !important;
                line-height: 35px !important;
                color: #666;
                border-radius: 5px;
            }
        }

        .box-header {
            width: 100%;
            height: 50px;
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }

        .box-body {
            width: 100%;
            border-radius: 5px;
            padding: 20px;
            box-sizing: border-box;
            box-shadow: 0 0 5px 0 #e4e4e4;

            .box-nav {
                width: 100%;
                height: 40px;
                line-height: 40px;
                padding-left: 10px;
                box-sizing: border-box;
                font-size: 14px;
                color: #666;
                border-left: 5px solid #1abc9c;
                background-color: #f9f9f9;
            }

            .body-top {
                width: 100%;
                height: 50px;
                text-align: center;
                line-height: 50px;
                border-bottom: 1px solid #e4e4e4;
                font-size: 20px;
                color: #666;
            }

            .body-set {
                margin-top: 20px;
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: flex-start;
            }

            .body-add {
                margin-top: 20px;
                width: 100%;
            }

            .body-table {
                margin-top: 20px;
                width: 100%;
            }

            .body-message {
                margin-top: 20px;
                width: 100%;

                .message-box {
                    margin-top: 20px;
                    display: flex;
                    align-items: center;
                    cursor: pointer;

                    .message-img {
                        margin-left: 20px;
                        width: 20px;
                        height: 20px;
                    }

                    .message-son {
                        margin-right: 15px;
                        font-size: 14px;
                    }
                }
            }
        }

        .box-submit {
            margin-top: 20px;
            width: 100%;
            border-radius: 5px;
            padding: 20px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-shadow: 0 0 5px 0 #e4e4e4;

            .submit-left {
                display: flex;
                font-size: 16px;

                p {
                    margin-right: 20px;

                    span {
                        color: red;
                        font-weight: bold;
                    }
                }
            }
        }
    }
</style>
